﻿var myarr = ""; var showMode = false; var timer;
function showSave(arg) {
    try {
        if (arg == true) {
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus2") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus2").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Saving data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus3") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus3").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Saving data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus4") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus4").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Saving data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus5") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus5").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Saving data...";
        }
        else {
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus2") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus2").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Updating data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus3") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus3").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Updating data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus4") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus4").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Updating data...";
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus5") != null)
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_lblStatus5").innerHTML = "&nbsp;<img src='Images/load.gif' border='0'></img>&nbsp;Updating data...";
        }
    }
    catch (ex) {}
}

function callPage(oList) {
    var sValue = oList.options[oList.selectedIndex].value;
    var sText = oList.options[oList.selectedIndex].text;
    var oListBox = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_SelChildPage")
    var anOption = document.createElement("OPTION");
    anOption.text = sText;
    anOption.value = sValue;
    oListBox.add(anOption);
}

function AddRowValue(strvalue, i) {
    addTagbind(''); //TO Bind the Jquery Drop down Box
    //            document.getElementById("div_cont").style.display = "block";
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value = strvalue;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_DelCount").value = "0";
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_update").style.visibility = "hidden";
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_update").style.display = "none"; // Added by 'Imran Gani' on 22-Jul-2013, for browser support.
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_save").style.visibility = "visible";
    var x = 0;
    for (x = 0; x < myarr.length; x++) {
        if (document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).getAttribute("type") == "checkbox") {
            if ((myarr[x] == "cb_list") || (myarr[x] == "cb_visible")) {
                document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).checked = true;
            }
            else {
                document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).checked = false;
            }
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value = "";
        }
        try {
            document.getElementById("ctl00_ContentPlaceHolder3_dd_typeobject").value = "TB";
            document.getElementById("ctl00_ContentPlaceHolder3_dd_datatype").value = "TX";
            document.getElementById("ctl00_ContentPlaceHolder3_dd_field_type").value = "USR"; // Added by 'Imran Gani' on 15-Jul-2013, for extended field type
        }
        catch (ex) {}
    }
    open1();
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_save").focus();
}

function SaveRowValue() {
    try {
        close1();
        var currpage;
        var count;
        var x = 0;
        currpage = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value;
        document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + currpage + "_RowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + currpage + "_RowCount").value) + 1;
    }
    catch (ex) {}
}

function Updatetot_page() {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_tot_page").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_tot_page").value) + 1;
}

function CancelValue() {
    close1();
    $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("");
    document.getElementById("div_cont").style.display = "none";
}

function UpdateRowValue() {
    //alert(myarr);
    close1();
    var x = 0;
    var currpage;
    currpage = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value;
    for (x = 0; x < myarr.length; x++) {
        if (myarr[x] == "txt_control_name") {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_control" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value;
        }
        else if (myarr[x] == "txt_size") {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_size" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value;
        }
        else if (myarr[x] == "dd_typeobject") {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_objecttype" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value;
        }
        else if (myarr[x] == "dd_datatype") {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_datatype" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value;
        }

        else if (myarr[x] == "dd_section_name")//Dhanapal
        {
            //document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_section_name" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value; 
            //document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + "lbl_section_name" + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).innerHTML = document.getElementById("ctl00_ContentPlaceHolder3_Tags").value; 
        }
        if (document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).getAttribute("type") == "checkbox") {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + myarr[x] + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).value = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).checked;
        }
        else {
            document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + currpage + myarr[x] + document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + currpage).value).value = document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value;
        }
    }
    document.getElementById("div_cont").style.display = "none";
}

function EditRowValue(strpage, strrow) {
    addTagbind('');
    // alert(myarr);
    if (showMode == true)
        return false;
    var x = 0;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value = strpage;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_updatecount_" + strpage).value = eval(strrow);
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_save").style.visibility = "hidden";
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_update").style.visibility = "visible";
    document.getElementById("ctl00_ContentPlaceHolder3_imgbtn_update").style.display = "inline-block";  // Added by 'Imran Gani' on 22-Jul-2013, for browser support.
    x = 0;
    for (x = 0; x < myarr.length; x++) {
        if (document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).getAttribute("type") == "checkbox") {
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + strpage + myarr[x] + strrow).value.toLowerCase() == "false") {
                document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).checked = false;
            }
            else {
                document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).checked = true;
            }
        }
        else {
            if (myarr[x] == "dd_section_name") {//Added By Dhanapal
                document.getElementById("ctl00_ContentPlaceHolder3_Tags").value = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + strpage + myarr[x] + strrow).value;
            } else {
                document.getElementById("ctl00_ContentPlaceHolder3_" + myarr[x]).value = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_" + strpage + myarr[x] + strrow).value;
            }
        }
    }
    open1();
}

function Clear_Del_Count() {
    var currpage;
    try {
        currpage = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value;
        document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + currpage + "_DelCount").value = "0";
    }
    catch (err) {}
}

function RemoveRowValue(strpage, strrow) {
    //alert("Am coming here" + "---" +  strpage + "----" + strrow);
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value = strpage;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strpage + "_DelCount").value = eval(strrow);
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strpage + "_RowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strpage + "_RowCount").value) - 1;
}

function RemoveRow(strvalue, i) {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_DelCount").value = eval(i);
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_RowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_RowCount").value) - 1;
}

function AddEventRowValue(strvalue) {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventRowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventRowCount").value) + 1;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventDelCount").value = 0;
}

function RemoveEventRow(strvalue, i) {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventDelCount").value = eval(i);
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventRowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_EventRowCount").value) - 1;
}

function AddChildRowValue(strvalue) {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildRowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildRowCount").value) + 1;
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildDelCount").value = 0;
}

function RemoveChildRow(strvalue, i) {
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildDelCount").value = eval(i);
    document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildRowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_pagewizard__sys" + strvalue + "_ChildRowCount").value) - 1;
}

// Added by srivatsan for auto fill of control id on control id
function SetControlID() {
    var currpage = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_update_page").value;
    if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_id") != null) {
        if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_name") != null) {
            if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_id").value == "") {
                document.getElementById("ctl00_ContentPlaceHolder3_txt_control_id").value = ReplaceVariablesInControl_id(document.getElementById("ctl00_ContentPlaceHolder3_txt_control_name").value);
            }
        }
    }
}

function ReplaceVariablesInControl_id(str) {
    //str = str.replace(" ","_");
    str = str.replace(/ /g, "_");
    return str;
}

/***Added BY Dhanapal On DEC282010 For Tree View Selection*************/
function EnableModeDropdown(obj) {
    var disablestatus = true;
    if (obj.checked) {
        disablestatus = false;
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlParentField")) {
        var ddlParentobj = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlParentField");
        //checkEnableStatus(ddlParentobj);
        ddlParentobj.disabled = disablestatus;
        //ddlParentobj.disabled = visiblestatus;
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlChildField")) {
        var ddlChildobj = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlChildField");
        //checkEnableStatus(ddlParentobj);
        ddlChildobj.disabled = disablestatus;
        //ddlChildobj.disabled = visiblestatus;
    }
}

function EnableCategoryDropdown(obj) {
    var disablestatus = true;
    if (obj.checked) {
        disablestatus = false;
    }
    if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlCategoryField")) {
        var ddlCategoryObj = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddlCategoryField");
        //checkEnableStatus(ddlParentobj);
        ddlCategoryObj.disabled = disablestatus;
        //ddlParentobj.disabled = visiblestatus;
    }
}

//implemented by sanal on Feb 15, 2008
var myWidth = 0;
var myHeight = 0;
var scrOfX = 0;
var scrOfY = 0;
var browserNetScape = false;
function setVariables() {
    if (navigator.appName == "Netscape")
        browserNetScape = true;
}
function loadthis() {
    setVariables();
}
function setWindowSize() {
    //var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );
}
function getScrollXY() {
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //return [ scrOfX, scrOfY ];
}
function close1() {
    showMode = false;
    document.getElementById("Panel1").style.display = "none";
    document.getElementById("div_cont").style.display = "none";
    clearTimeout(timer);
}
function open1() {
    setVariables();
    showMode = true;
    setWindowSize();
    getScrollXY();
    document.getElementById("Panel1").style.display = "block";
    //document.getElementById("Panel1").style.visibility = "visible";  
    document.getElementById("div_cont").style.display = "block";
    //document.getElementById("pnlContent").style.visibility = "visible";        
    if (browserNetScape == true) {
        document.getElementById("Panel1").style.width = '';
        document.getElementById("Panel1").style.left = '';
        document.getElementById("Panel1").style.top = '';
        document.getElementById("Panel1").style.height = '';
        document.getElementById("Panel1").style.left = "0px";
        document.getElementById("Panel1").style.top = "0px";
        document.getElementById("Panel1").style.width = (myWidth + scrOfX - 8) + "px";
        document.getElementById("Panel1").style.height = (myHeight + scrOfY - 8) + "px";
        var lef = ((myWidth - document.getElementById("div_cont").offsetWidth) / 2);
        var top = (myHeight - document.getElementById("div_cont").offsetHeight) / 2 + scrOfY;
        document.getElementById("div_cont").style.left = lef + "px";
        document.getElementById("div_cont").style.top = top + "px";
    }
    else {
        document.getElementById("Panel1").style.left = "0";
        document.getElementById("Panel1").style.top = "0";
        document.getElementById("Panel1").style.width = myWidth + scrOfX;
        document.getElementById("Panel1").style.height = myHeight + scrOfY;
        document.getElementById("div_cont").style.left = (myWidth - document.getElementById("div_cont").offsetWidth) / 2;
        //document.getElementById("div_cont").style.top = "0";
        document.getElementById("div_cont").style.top = (myHeight - document.getElementById("div_cont").offsetHeight) / 2;
    }
    if (showMode == true) timer = setTimeout("open1()", 300);
    return false;
}

function showpageicon() {
    var selectedtext = "";
    try {
        if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddpageicon") != null) {
            selectedtext = document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ddpageicon").value;
        }
        if (selectedtext != "") {
            if (document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ImgIcon") != null) {
                document.getElementById("ctl00_ContentPlaceHolder3_pagewizard_ImgIcon").src = "Images/MBIcons/medium/" + selectedtext;
            }
        }
    }
    catch (err) {}
}

function CheckForRequiredFields() {
    //alert("CheckForRequiredFields");
    if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_name") != null)
        if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_name").value == "") {
            document.getElementById("ctl00_ContentPlaceHolder3_vld").style.visibility = "block";
            $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("<div class=\"mbMessage\"><img src=\"Images/error.gif\" alt=\"\" />&nbsp;Control Name should not be empty value.</div>");
            return false;
        }
    if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_id") != null)
        if (document.getElementById("ctl00_ContentPlaceHolder3_txt_control_id").value == "") {
            document.getElementById("ctl00_ContentPlaceHolder3_vld_control_id").style.visibility = "block";
            $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("<div class=\"mbMessage\"><img src=\"Images/error.gif\" alt=\"\" />&nbsp;Control ID should not be empty value.</div>");
            return false;
        }
        if (document.getElementById("ctl00_ContentPlaceHolder3_dd_typeobject") != null)
            if (document.getElementById("ctl00_ContentPlaceHolder3_dd_typeobject").value == "DL") {
                if (document.getElementById("ctl00_ContentPlaceHolder3_dd_databind") != null)
                    if (document.getElementById("ctl00_ContentPlaceHolder3_dd_databind").value != "") {
                        document.getElementById("ctl00_ContentPlaceHolder3_vld").style.visibility = "block";
                        $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("<div class=\"mbMessage\"><img src=\"Images/error.gif\" alt=\"\" />&nbsp;Droplist will not support data bind values.</div>");
                        return false;
                    }
                if (document.getElementById("ctl00_ContentPlaceHolder3_ta_droplist") != null)
                    if (document.getElementById("ctl00_ContentPlaceHolder3_ta_droplist").value == "") {
                        document.getElementById("ctl00_ContentPlaceHolder3_vld").style.visibility = "block";
                        $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("<div class=\"mbMessage\"><img src=\"Images/error.gif\" alt=\"\" />&nbsp;Droplist Values should not be empty.</div>");
                        return false;
                    }
            }
    $("#ctl00_ContentPlaceHolder3_lblCtrMsg").html("");
    return true;
}

function savecontrol(isNewControl) {
    try {
        if (!CheckForRequiredFields())
            return false;
        if (isNewControl) {
            showSave(true);
            SaveRowValue();
        }
        else {
            showSave(false); 
            UpdateRowValue();
        }
    }
    catch (err) { }
}